package com.zenika.zenbinding.client.validator;

import com.zenika.zenbinding.client.exception.DataMessage;
import com.zenika.zenbinding.client.exception.ValidatorException;

public class RegexpValidator implements Validator {

	private RegExp regexp;

	public RegexpValidator(String mask) {
		this.regexp = RegExp.create(mask);
	}

	public void validate(Object object) throws ValidatorException {
		String value = (String) object;
		boolean test = this.regexp.test(value);
		if (!test) {
			DataMessage message = new DataMessage("Incorrect format");
			throw new ValidatorException(message);
		}
	}

}
